Ext.define('AmpleHarvest.objects.forms.osSearch',
{
	extend				: 'Ext.form.Panel',
	alias				: 'widget.ampleharvest-objects-forms-ossearch',
	source_name			: 'OCTOBERSKY',
	border				: false,
	requires			:
	[
			"Ext.button.Button", 
			"Ext.form.field.Text", 
			"Ext.form.FieldSet",
			"Ext.form.field.Date", 
			'Ext.form.ComboBox',
			"AmpleHarvest.elements.combobox.cFacet"
	],
	statics				:
	{
		C_STR_FIELD_COST		: "value.cost",
		C_STR_FIELD_CUSTOMER	: "string.customer",
		C_STR_FIELD_ORDERMETHOD	: "string.order_method",
		C_STR_FIELD_PUBLISHDATE	: "publish_date",
		C_STR_FIELD_HARVESTDATE	: "harvest_date",
		C_STR_FIELD_INDEXDATE	: "index_date",
		C_STR_FIELD_SOURCE		: "source",
		C_STR_DATATYPE_FACET	: "facet"

	},
	
	m_arr_StateEvents	: [],

	initComponent			: function()
	{
		
		// The store below pulls back all of the constant data from cDoc via REST and can be used to fill out the entity names
		//this.solr_constants = Ext.create("AmpleHarvest.DATA.Store.solr.cDoc");
		//this.dockedItems = [];
//		this.buttons = [];
		
		this.PublishDateBox = Ext.create("Ext.form.FieldSet",
				{
					title		: "Publish Date",
					collapsible	: true,
					labelWidth	: 70,
					boxMinWidth	: 275,
					stateId		: this.self.C_STR_FIELD_PUBLISHDATE,
					stateful	: false,
					listeners	:
					{
//						resize	:
//						{
//							fn	: function()
//							{
//								this.up('form').save_State();
//							}
//						}
					}
				});

		this.PublishDateBox.add(Ext.create("Ext.form.field.Date",
		{
			fieldLabel	: "Start Date",
			format		: 'Y-m-d H:i:s',
			dataType	: this.self.C_STR_DATATYPE_DATE,
			dataType	: 'date',
			anchor		: "100%",
			name		: this.self.C_STR_FIELD_PUBLISHDATE + "_start",
//			itemId		: this.self.C_STR_FIELD_PUBLISHDATE + "_start",
			searchTerm	: this.self.C_STR_FIELD_PUBLISHDATE,
			allowBlank	: true
		}
		));

		this.PublishDateBox.add(Ext.create("Ext.form.field.Date",
		{
			fieldLabel	: "End Date",
			format		: 'Y-m-d H:i:s',
			dataType	: this.self.C_STR_DATATYPE_DATE,
			dataType	: 'date',
			anchor		: "100%",
			name		: this.self.C_STR_FIELD_PUBLISHDATE + "_end",
//			itemId		: this.self.C_STR_FIELD_PUBLISHDATE + "_end",
			searchTerm	: this.self.C_STR_FIELD_PUBLISHDATE,
			allowBlank	: true
		}
		));

//		this.buttons.push(
//				 Ext.create("Ext.button.Button",
//			      {
//			         text     : 'Save Query',
//			         disabled : true,
//			         scope    : this,
//			         handler     : function()
//			         {
//			            this.up('ampleharvest-objects-search-panel-csearch').fireEvent(
//			                        AmpleHarvest.eventHandler.cWindowEvents.C_STR_EVENT_SAVED_QUERY_ADD,
//			                        this.ownerCt.ownerCt.get_JsonQuery(),
//			                        this.m_str_SourceGUID
//			                  );
//			         }
//			      }),
//		         Ext.create("Ext.button.Button",
//		         {
//		            text  : "Reset",
//		            handler  : function()
//		            {
//		               this.ownerCt.ownerCt.reset_Query();
//		            },
//		            scope : this
//		         }), 
//		         Ext.create("Ext.button.Button",
//		         {
//		            text  : "Search",
//		            handler  : function()
//		            {
//		               this.enableBubble('do_Search');
//		               this.fireEvent("do_Search", this.get_QueryObject());
//		               //this.ownerCt.ownerCt.do_Search();
//		            },
//		            scope : this
//		         })
//		      );
		this.items =
		[
				Ext.create("Ext.form.field.Text",
						{
							fieldLabel	: "General",
							id			: 'ampleHarvest-objects-forms-textarea'+this.str_unique_id,
//							itemId		: 'general',
							name		: "general",
							hiddenName	: "general",
							inputType	: "textfield",
							allowBlank	: true,
							anchor		: "100%"
						}
				), 
				
				Ext.create("AmpleHarvest.util.cPropertiesDropDown",
						{
							fieldLabel	: "Source",
							name		: 'source',
//							itemId		: 'source',
							targetPath	: this.str_solr_base,
							valueField	: 'facet',
							searchTerm	: this.self.C_STR_FIELD_SOURCE,
							dataType	: this.self.C_STR_DATATYPE_FACET,
							anchor		: '92%',
							emptyText	: 'Enter Source',
						}
					), 

				this.PublishDateBox
		]
        this.callParent();
		 
	},

	load_FromJson		: function(obj_Json)
	{
		for (var int_I = 0; int_I < obj_Json.Query.length; int_I++)
		{
			if (obj_Json.Query[int_I].property == "read")
			{
				if (obj_Json.Query[int_I].condition == "!=")
				{
					this.set_FieldValue("read", "unread");
				}
				else
				{
					this.set_FieldValue("read", "read");
				}

			}
			else
			{
				var str_name = obj_Json.Query[int_I].property;
				if (obj_Json.Query[int_I].prefix)
				{
					str_name += "_"
							+ obj_Json.Query[int_I].prefix.substr(0,
									obj_Json.Query[int_I].prefix.length - 1
							);
				}

				this.set_FieldValue(str_name, obj_Json.Query[int_I].value);
			}
		}
	}
}
);